// praxis/hardware/simulated_actuator.cc
#include "praxis/hardware/simulated_actuator.h"

#include <algorithm>

namespace praxis {
CSimulatedActuator::CSimulatedActuator(const std::string& name,
                                       const std::string& unit,
                                       double initial_value,
                                       double change_rate_per_second)
    : name_(name),
      unit_(unit),
      current_value_(initial_value),
      target_value_(initial_value),
      max_change_per_update_(change_rate_per_second * 0.5) {
}  // 500ms update interval

const std::string& CSimulatedActuator::GetName() const { return name_; }

double CSimulatedActuator::GetCurrentValue() const { return current_value_; }

void CSimulatedActuator::SetTarget(double target) { target_value_ = target; }

void CSimulatedActuator::Update() {
  if (current_value_ < target_value_) {
    current_value_ =
        std::min(target_value_, current_value_ + max_change_per_update_);
  } else if (current_value_ > target_value_) {
    current_value_ =
        std::max(target_value_, current_value_ - max_change_per_update_);
  }
}
}  // namespace praxis